<template>
	<view class="shopDetail" v-if="detail">
		<image class="goBack" @click="goBack(1)" :src="imgUrl+'18.png'" mode="widthFix"></image>
		<view class="t1">
			<image :src="detail && detail.images[0]"></image>
		</view>
		<view class="t2">
			<view class="t3">
				<view class="t4">
					{{detail.title}}
				</view>
				<view class="t5">
					<label @click="lickFn">
						<view>
							<image
								:src="collected?'https://hongpei.oss-cn-hangzhou.aliyuncs.com/img/13.png':'https://hongpei.oss-cn-hangzhou.aliyuncs.com/img/15.png'"
								mode="widthFix"></image>
						</view>
						<view>喜欢</view>
					</label>
					<!-- <view class="rule" @click="show=true">选规格</view> -->
				</view>
			</view>
			<view class="t6">
				<image :src="imgUrl+'9.png'" mode="widthFix"></image>
			</view>
			<view class="t7">
				￥{{detail.costPrice}} <text>¥ {{detail.price}}</text>
			</view>
			<view class="t8">
				{{detail.subTitle}}
			</view>
		</view>
		<view class="t9">
			<view class="t10">
				商品详情
			</view>
			<view class="bg">

				<u-parse :content="detail.content"></u-parse>
				<view class="sq1" v-if="buyText=='已售罄'">
					商品已售罄
				</view>
				
			</view>
		</view>
		<view class="btn">
			<view class="b1"  @click="show=true">
				规格
				<text v-if="detail.salePropertyList && detail.salePropertyList[0].itemList[idx2]">{{detail.salePropertyList[0].itemList[idx2].propertyValue}}</text>
				<image :src="imgUrl+'back@2x.png'" mode="widthFix"></image>
			</view>
			<view class="b2" @click="show=true">
				购买
			</view>
		</view>
		<u-popup :show="show" @close="show=false">
			<buy :detail="detail" @buyTextFn="buyTextFn" :store="store" @idxFn="idxFn" />
		</u-popup>
		<u-popup :show="show2" @close="show2=false">
			<cart />
			<view class="btn">
				<view class="b1">
					<view class="bImg">
						<image :src="imgUrl+'23.png'" mode="widthFix"></image>
						<view>0</view>
					</view>
					<image class="img5" :src="imgUrl+'9.png'" mode="widthFix"></image>
					<text>¥68</text>
					<text>¥76</text>
				</view>
				<view class="b2" @click="goTo('/pages/home/placeOrder')">
					购买
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import buy from './components/buy.vue';
	import cart from './components/cart.vue';
	export default {
		data() {
			return {
				show: false,
				imgUrl: this.imgUrl,
				show2: false,

buyText:"",
				productid: "",
				detail: "",
				collected: false,
				store: {},
				idx2:0


			}
		},
		components: {
			buy,
			cart
		},
		onLoad(e) {
			this.productid = e.productid
			
			this.store=	uni.getStorageSync("store")

			this.GetDetail()

		},
		methods: {
			buyTextFn(e){
				this.buyText=e
				console.log(e)
				
			},
			idxFn(e){
				this.idx2=e
				
			},
			lickFn() {
				if(!uni.getStorageSync("isLogin")){
					uni.showModal({
						content:"您还没有登录，请先登录！",
						success(res){
							if(res.confirm){
								uni.navigateTo({
									url:"/pages/commer/wxlogin"
								})
							}
						}
					})
					return
				}
				if (this.collected) {
					this.$http.CancelCollect({
						productBaseId: this.detail.productBaseId,
					}).then(res => {
						uni.showToast({
							title: '已取消喜欢',
							icon: 'none'
						})
						this.GetDetail()

					})
				} else {
					this.$http.AddCollect({
						productBaseId: this.detail.productBaseId,
					}).then(res => {
						uni.showToast({
							title: '已添加到我的喜欢',
							icon: 'none'
						})
						this.GetDetail()

					})
				}

			},
			CheckCollect() {
				this.$http.CheckCollect({
					productBaseId: this.detail.productBaseId,
				}).then(res => {
					this.collected = res.content.collected

				})
			},
			GetDetail() {
				this.$http.GetDetail({
					productid: this.productid,
					storeid: this.store.storeId,
				}).then(res => {
					res.content.salePropertyList.forEach(function(e, idx) {
						e['active'] = 0;
					})
					
					
					this.detail = res.content
					if(uni.getStorageSync("isLogin")){
						this.CheckCollect()
					}

				})
			}

		}
	}
</script>

<style scoped lang="scss">
	.shopDetail {
		.goBack {
			width: 50upx;
			height: 50upx;
			position: absolute;
			left: 30upx;
			top: 80upx;
		}

		.t1 {
			image {
				width: 100%;
				height: 700upx;
			}
		}

		.t2 {
			padding: 28upx;
			background: #FFFFFF;
			margin-top: -30upx;
			position: relative;
			z-index: 2;
			box-shadow: 0px -2upx 16upx 0px rgba(204, 204, 204, 0.5);
			border-radius: 20upx 20upx 0px 0px;

			.t3 {
				display: flex;
				justify-content: space-between;

				.t4 {
					font-size: 36upx;
					font-weight: 400;
					color: #222222;
				}

				.t5 {
					font-size: 18upx;
					font-weight: 400;
					color: #BFB49B;
					text-align: center;
					margin-right: 40upx;
					margin-top: 20upx;

					image {
						width: 38upx;
						height: 32upx;
					}

					.rule {
						width: 120upx;
						height: 48upx;
						line-height: 48upx;
						background: linear-gradient(270deg, #01AD65 0%, #01AD65 65%, #01AD65 100%);
						border-radius: 100upx;
						font-size: 24upx;
						font-weight: 400;
						color: #F8F7F7;
						margin-top: 20upx;
					}
				}


			}

			.t6 {

				image {
					width: 56upx;
					height: 27upx;
				}
			}

			.t7 {
				font-size: 32upx;
				font-weight: 400;
				margin-top: 6upx;
				color: #222222;

				text {
					font-size: 20upx;
					font-weight: 400;
					color: #888888;
					margin-left: 10upx;
				}
			}

			.t8 {
				font-size: 26upx;
				font-weight: 400;
				color: #888888;
				margin-top: 10upx;
			}
		}

		.t9 {
			background: #fff;
			padding-bottom: 100upx;

			.t10 {
				color: #333;
				font-size: 32upx;
				padding: 30upx 0;
				text-align: center;
				position: relative;
				width: 150upx;
				margin: 0 auto 20upx;

			}

			.t10:before {
				content: '';
				display: block;
				height: 3px;
				width: 84upx;
				position: absolute;
				bottom: 6upx;
				left: 30upx;
				background: #01AD65;
				border-radius: 10upx;
			}
		}
	}

	.btn {
		width: 99%;
		height: 98upx;
		background: rgba(255, 255, 255, 0.95);
		box-shadow: 0px -1px 8upx 0px rgba(211, 211, 211, 0.71);
		border-radius: 49upx;
		position: fixed;
		bottom: 0;
		margin: 0;
		z-index: 10000;
		left: 50%;
		margin-left: -370upx;
		display: flex;
		align-items: center;
		justify-content: space-between;

		.b1 {
			font-size: 26upx;
			font-weight: 400;
			padding-left: 33upx;
			color: #888888;

			text {
				font-size: 32upx;
				font-weight: 400;
				color: #BFB49B;
				margin: 0 10upx;
			}

			image {
				width: 20upx;
				height: 20upx;
			}

		}

		.b2 {
			width: 240upx;
			height: 80upx;
			line-height: 80upx;
			background: linear-gradient(270deg, #01AD65 0%, #01AD65 65%, #01AD65 100%);
			border-radius: 100upx;
			font-size: 32upx;
			font-weight: 400;
			color: #F8F7F7;
			margin-right: 10upx;
		}
	}
	.sq1{
		background: rgba(0,0,0,.5);
		width: 100%;
		height: 270upx;
		text-align: center;
		color: #fff;
		font-size: 32upx;
		padding:70upx 30upx;
		position: fixed;
		bottom: 0;
	}
</style>
